import 'package:flui/flui.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:share/share.dart' as PageShare;

class Share extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _ShareState();
  }
}

//分享文本
//PageShare.Share.share("text");
class _ShareState extends State<Share> {
  FLToastDefaults _toastDefaults = FLToastDefaults();
  List<String> _imageHttpsList = [
    "https://fanbei-pro.oss-cn-hangzhou.aliyuncs.com/upload/dev/img/090e65b103ef42368fefacbb33e7ac26.jpeg",
    "https://fanbei-pro.oss-cn-hangzhou.aliyuncs.com/upload/dev/img/81dbfdabdea54acd8a2d44bc47ab44e5.png",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color.fromRGBO(247, 247, 247, 1),
        elevation: 0,
        title: Text('邀请好友'),
      ),
      body: FLToastProvider(
          defaults: _toastDefaults,
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              new Expanded(
                child: new SingleChildScrollView(
                  child: new Column(
                    children: <Widget>[
                      Container(
                        padding: const EdgeInsets.only(top: 10),
                        height: 550, // 高度
                        child: Swiper(
                          scrollDirection: Axis.horizontal,
                          // 横向
                          itemCount: _imageHttpsList.length,
                          // 数量
                          autoplay: false,
                          // 自动翻页
                          itemBuilder: (BuildContext context, int index) {
                            // 构建
                            return Container(
                              margin: const EdgeInsets.only(bottom: 30),
                              decoration: BoxDecoration(
                                  image: DecorationImage(
                                      image:
                                          NetworkImage(_imageHttpsList[index]),
                                      fit: BoxFit.fill),
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(10))),
                            );
                          },
                          onTap: (index) {
                            print('点击了第${index}');
                          },
                          // 点击事件 onTap
                          viewportFraction: 0.8,
                          // 当前视窗展示比例 小于1可见上一个和下一个视窗
                          scale: 0.8,
                          // 两张图片之间的间隔
                          layout: SwiperLayout.STACK,
                          itemWidth: MediaQuery.of(context).size.width - 80,
                          itemHeight: MediaQuery.of(context).size.height,
                        ),
                      ),
                      new Container(
                        width: 200.0,
                        height: 50.0,
                        padding: EdgeInsets.all(10.0),
                        child: new Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            new Text('邀请码'),
                            new Text(
                              "15625",
                              style: TextStyle(
                                fontSize: 18.0,
                                color: Colors.white,
                              ),
                            ),
                            new InkWell(
                              onTap: () {
                                Clipboard.setData(
                                    ClipboardData(text: '复制到剪切板'));
                                FLToast.showText(text: '复制成功');
                              },
                              child: new Container(
                                alignment: Alignment.center,
                                width: 40.0,
                                height: 25.0,
                                child: new Text(
                                  "复制",
                                  style: TextStyle(fontSize: 12.0),
                                ),
                                decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius: BorderRadius.circular(5.0)),
                              ),
                            )
                          ],
                        ),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          image: new DecorationImage(
                            image: new AssetImage("images/share/yqm.png"),
                            //这里是从assets静态文件中获取的，也可以new NetworkImage(）从网络上获取
                            centerSlice:
                                new Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),
                          ),
                        ),
                      ),
                      new Container(
                        padding: EdgeInsets.all(10.0),
                        alignment: Alignment.centerLeft,
                        child: new Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: <Widget>[
                            new Text(
                              "1： 复制邀请码发给好友下载App注册时填写。\n"
                              "2： 转发邀请还白，好友通过识别看报二维码下载APP并登录微信\n"
                              "3： 转发邀请还白，好友通过识别看报二维码下载APP并",
                              style: TextStyle(fontSize: 15.0),
                            ),
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ),
              new Container(
                height: 100.0,
                color: Color.fromRGBO(247, 247, 247, 1),
                padding: EdgeInsets.all(10.0),
                child: new Flex(
                  direction: Axis.horizontal,
                  children: <Widget>[
                    _shareButtom("images/share/lianjie.png", "链接"),
                    _shareButtom("images/share/wx.png", "微信"),
                    _shareButtom("images/share/pyq.png", "朋友圈"),
                    _shareButtom("images/share/qq.png", "QQ"),
                  ],
                ),
              ),
            ],
          )),
    );
  }

  Widget _shareButtom(
    String src,
    String title,
  ) {
    return Expanded(
        child: new InkWell(
      child: new Column(children: <Widget>[
        new Image.asset(
          src,
          width: 50.0,
        ),
        new SizedBox(height: 10.0),
        new Text(title)
      ]),
      onTap: () {},
    ));
  }
}
